﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace PTop.Domain.ViewModel.Bus
{
    /// <summary>
    /// 公交线路位置模型
    /// </summary>
    [Serializable]
    public class LineAndStopLocationModel
    {
        public int LineId { get; set; }

        public string LineName { get; set; }

        public string Direction { get; set; }

        /// <summary>
        /// 从始发站到终点站的线路经纬度列表
        /// </summary>
        public List<LocPoint> LocPoints { get; set; }

        /// <summary>
        /// 获取position从startPosition到endPosition的序列
        /// </summary>
        /// <param name="startPosition"></param>
        /// <param name="endPosition"></param>
        /// <returns></returns>
        public List<LocPoint> GetPartPoints(int startPosition, int endPosition)
        {
            var startPoint = LocPoints.First(m => m.IsStop && m.Position == startPosition);
            var startIndex = LocPoints.IndexOf(startPoint);
            var endPoint = LocPoints.First(m => m.IsStop && m.Position == endPosition);
            var endIndex = LocPoints.IndexOf(endPoint);
            var partList = LocPoints.Skip(startIndex).Take(endIndex - startIndex + 1).ToList();
            return partList;
        }

        public List<StopLocationModel> StopLocations { get; set; }
    }

    public class StopLocationModel
    {
        public int StopId { get; set; }

        public string StopName { get; set; }

        public int StopNo { get; set; }

        public int Position { get; set; }

        public double Lng { get; set; }

        public double Lat { get; set; }
    }

}
